#ifndef _CAMERA_MANIPULATOR_H_
#define _CAMERA_MANIPULATOR_H_

#include <osgGA/MatrixManipulator>

class CameraManipulator : public osgGA::MatrixManipulator
{
public:
	CameraManipulator();

    /** set the position of the matrix manipulator using a 4x4 Matrix.*/
	virtual void setByMatrix(const osg::Matrixd& matrix) { m_Matrix = matrix; }

    /** set the position of the matrix manipulator using a 4x4 Matrix.*/
	virtual void setByInverseMatrix(const osg::Matrixd& matrix) { m_Matrix = osg::Matrix::inverse(matrix); }

    /** get the position of the manipulator as 4x4 Matrix.*/
	virtual osg::Matrixd getMatrix() const { return m_Matrix; }

    /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
	virtual osg::Matrixd getInverseMatrix() const { return osg::Matrix::inverse(m_Matrix); }

    /**
    Move the camera to the default position. 
    May be ignored by manipulators if home functionality is not appropriate.
    */
	virtual void home(const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&);

	/** Handle events, return true if handled, false otherwise. */
	virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);

private:
	enum State { None, Dragging };

	State m_State;
	osg::Vec2 m_LastMousePosition;
	osg::Vec3 m_LastPosition;
	osg::Matrix m_Matrix;
};

#endif
